﻿using Nuctech.ACCT.OIS.Event.Application.Contracts.Event.DTO.EventData;
using SharedModule;
using System.Text.Json;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;

namespace 发布日志
{
    public class EventMessagingService : ITransientDependency
    {
        private readonly IDistributedEventBus _distributedEventBus;

        public EventMessagingService(IDistributedEventBus distributedEventBus)
        {
            _distributedEventBus = distributedEventBus;
        }

        public async Task RunAsync()
        {
            Console.WriteLine("*** 发布日志项目启动 ***");
            Console.WriteLine("*** 选择下面操作： ***");
            Console.WriteLine("*** 1: 发布一条日志事件 ***");
            Console.WriteLine("*** 2: 发布10条日志事件 ***");
            Console.WriteLine("*** 3: 发布10条管理日志事件 ***");
            Console.WriteLine("*** 4: 发布10条设备日志事件 ***");
            Console.WriteLine("*** 5: 发布10条预检日志事件 ***");
            Console.WriteLine("*** 6: 发布10条判图日志事件 ***");

            string message;
            do
            {
                Console.WriteLine();

                message = Console.ReadLine();

                if (message.Equals("1"))
                {
                    //待发送消息
                    EventCreatePostDto eventCreatePostDto = new EventCreatePostDto()
                    {
                        StationType = StationTypeEnum.SttSmsc,
                        UserId = 2,
                        EventLevel = EventLevelEnum.Info,
                        EventSubType = EventSubTypeEnum.Login,
                        DesTemplateId = 137740943366,
                        CreateTime = DateTime.UtcNow,
                        Des = JsonSerializer.Serialize(
                                    new EventKeyInfoDto
                                    {
                                        KeyInfos = new List<KeyInfo>
                                        {
                                            new KeyInfo
                                            {
                                                Index = 0,
                                                NeedTranslation = false,
                                                Params = "s1",
                                            }
                                        }
                                    }),
                    };

                    //await _distributedEventBus.PublishAsync(eventCreatePostDto);
                    await _distributedEventBus.PublishAsync(new EventLogData(eventCreatePostDto));
                    await Console.Out.WriteLineAsync("发送成功！");
                }
                if (message.Equals("2"))
                {
                    int i = 1;
                    while (i <= 10)
                    {
                        //待发送消息
                        EventCreatePostDto eventCreatePostDto = new EventCreatePostDto()
                        {
                            StationType = StationTypeEnum.SttSmsc,
                            UserId = 2,
                            EventLevel = EventLevelEnum.Info,
                            EventSubType = EventSubTypeEnum.Login,
                            DesTemplateId = 137740943366,
                            ErrCode = i,
                            CreateTime = DateTime.UtcNow,
                            Des = JsonSerializer.Serialize(
                                    new EventKeyInfoDto
                                    {
                                        KeyInfos = new List<KeyInfo>
                                        {
                                            new KeyInfo
                                            {
                                                Index = 0,
                                                NeedTranslation = false,
                                                Params = "s1",
                                            }
                                        }
                                    }),
                        };

                        //await _distributedEventBus.PublishAsync(eventCreatePostDto);
                        await _distributedEventBus.PublishAsync(new EventLogData(eventCreatePostDto));
                        await Console.Out.WriteLineAsync("第" + i + "次发送成功！");
                        i++;
                    }
                }
                if (message.Equals("3"))
                {
                    int i = 1;
                    while (i <= 10)
                    {
                        //待发送消息
                        SMSEventData sMSEventData = new SMSEventData()
                        {
                            StationType = StationTypeEnum.SttSmsc,
                            UserId = 2,
                            EventLevel = EventLevelEnum.Info,
                            EventSubType = EventSubTypeEnum.Login,
                            DesTemplateId = 137740943366,
                            ErrCode = i,
                            CreateTime = DateTime.UtcNow,
                        };

                        //await _distributedEventBus.PublishAsync(eventCreatePostDto);
                        await _distributedEventBus.PublishAsync(sMSEventData);
                        await Console.Out.WriteLineAsync("第" + i + "次管理日志发送成功！");
                        i++;
                    }
                }
                if (message.Equals("4"))
                {
                    int i = 1;
                    while (i <= 10)
                    {
                        //待发送消息
                        DMSEventData sMSEventData = new DMSEventData()
                        {
                            StationType = StationTypeEnum.SttSmsc,
                            UserId = 2,
                            EventLevel = EventLevelEnum.Info,
                            EventSubType = EventSubTypeEnum.Login,
                            DesTemplateId = 137740943366,
                            ErrCode = i,
                            CreateTime = DateTime.UtcNow,
                        };

                        //await _distributedEventBus.PublishAsync(eventCreatePostDto);
                        await _distributedEventBus.PublishAsync(sMSEventData);
                        await Console.Out.WriteLineAsync("第" + i + "次设备日志发送成功！");
                        i++;
                    }
                }

                if (message.Equals("5"))
                {
                    int i = 1;
                    while (i <= 10)
                    {
                        //待发送消息
                        PISEventData sMSEventData = new PISEventData()
                        {
                            StationType = StationTypeEnum.SttSmsc,
                            UserId = 2,
                            EventLevel = EventLevelEnum.Info,
                            EventSubType = EventSubTypeEnum.Login,
                            DesTemplateId = 137740943366,
                            ErrCode = i,
                            CreateTime = DateTime.UtcNow,
                        };

                        //await _distributedEventBus.PublishAsync(eventCreatePostDto);
                        await _distributedEventBus.PublishAsync(sMSEventData);
                        await Console.Out.WriteLineAsync("第" + i + "次预检日志发送成功！");
                        i++;
                    }
                }

                if (message.Equals("6"))
                {
                    int i = 1;
                    while (i <= 10)
                    {
                        //待发送消息
                        IPSEventData sMSEventData = new IPSEventData()
                        {
                            StationType = StationTypeEnum.SttSmsc,
                            UserId = 2,
                            EventLevel = EventLevelEnum.Info,
                            EventSubType = EventSubTypeEnum.Login,
                            DesTemplateId = 137740943366,
                            ErrCode = i,
                            CreateTime = DateTime.UtcNow,
                        };

                        //await _distributedEventBus.PublishAsync(eventCreatePostDto);
                        await _distributedEventBus.PublishAsync(sMSEventData);
                        await Console.Out.WriteLineAsync("第" + i + "次判图日志发送成功！");
                        i++;
                    }
                }
            } while (!message.IsNullOrEmpty());
        }
    }
}